$(function() {
	var times= Date.parse(new Date());
var timestamp = Math.round(new Date().getTime()/1000),nonce = randomString(5),appkey = '2ef161ba0bd02b6c4c399826d941eb804ad8376d',
signature = sha1(timestamp + nonce + appkey);
// console.log('signature=' + signature);
// console.log('时间戳=' + timestamp + '+nonce=' + nonce + '+appkey=' + appkey);
function randomString(len) {　　
	len = len || 32;　　
	var $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';　　
	var maxPos = $chars.length;　　
	var pwd = '';　　
	for (i = 0; i < len; i++) {
		//0~32的整数  
		pwd += $chars.charAt(Math.floor(Math.random() * (maxPos + 1)));　　
	}　　
	return pwd;
}
	/*焦点效果切换*/
	var focus_sw = function() {};
	focus_sw.prototype = {
		//提示
		showtip: function(obj) {
			var check = '';
			if($('.stip').length < 1) {
				var divn = document.createElement('div');
				divn.className = 'stip';
				divn.innerHTML = '<span></span>';
				document.body.appendChild(divn);
			}
			$('.stip').show();
			$('.stip span').html(obj);
			check = setTimeout(function() {
				$('.stip').hide();
				$('.stip span').html('');
			}, 1800);
			return this;
		},
		onfocus: function() {
			/*聚焦变色*/
			$("input").focus(function() {
				var that=this;
				$(this).css({
					"background": "#fff",
					"color": "#3db7f6"
				});
				$(this).next("b").css("display", "block");
				
				if($(this).prev("i").hasClass("count")) {
					$(this).prev("i").addClass("count_s").parent().siblings().find("i").removeClass("psw_s");
				} else {
					$(this).prev("i").addClass("psw_s").parent().siblings().find("i").removeClass("count_s");
				}
				/*setTimeout(function(){
					that.pannel.scrollIntoView(true);
					that.pannel.scrollIntoViewIfNeeded();
					alert("键盘");
				},200);*/
			})
			return this;
		},
		onblur: function() {
			$("input").blur(function() {
				$(this).css({
					"background": "##e3ebec",
					"color": "#999"
				});
				$(this).next("b").css("display", "none");
			});
			return this;
		}
	}
	var focs_s = new focus_sw();
	focs_s.onfocus().onblur().showtip;

	/*登陆*/
	var login_btn = function() {};
	login_btn.prototype = {
		login_Btn: function() {
			var url = "http://admin.api.test.51bbc.cn/index/user/login",storage = window.localStorage;
			$(".login_btn").click(function() {
				var cout = $("input[name='count']").val(),
					psw = $("input[name='passworld']").val();
				if(cout.length == 0 || cout == "") {
					focs_s.showtip("请输入账号!");
				} else if(psw.length == 0) {
					focs_s.showtip("请输入密码!");
				} else {
					
					$.get(url, {
						nonce: nonce, timestamp: timestamp, signature: signature, username: cout, password:psw
					},function(res) {
						console.log(JSON.parse(res));
						var data=JSON.parse(res);
						if(data.code==200){
							focs_s.showtip(data.message);
							storage.setItem("token", data.data.token); 
								location.href='./index.html';
						}else{
							focs_s.showtip(data.message);
						}
					})
				
				}
			})
		}
	}
	var login_c = new login_btn();
	login_c.login_Btn();
	
	/*针对ios键盘遮挡处理*/
var isIOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //判断是iOS  
if(isIOS) {
	function keyboardShowHandler(e) {
		if(window.scrollY < 100) //键盘高度一般大于100，如果scrollY小于100，可以认为界面未上移，则需要手动上移  
			window.scrollTo(0, e.keyboardHeight);
			alert("上移了"+e.keyboardHeight);
	}

	function keyboardHideHandler(e) {
		if(window.scrollY != 0)
			window.scrollTo(0, 0);
	}
	window.addEventListener('native.keyboardshow', keyboardShowHandler);
	window.addEventListener('native.keyboardhide', keyboardHideHandler);
}
})